#pragma once
#include "base.h"
#include "Renderer.h"
#include "ScreenManager.h"
#include "IGame.h"
#include "IModLoader.h"
#include "Timer.h"
#include "FPSCounter.h"
class Game : public IGame
{
public:
	Game();
	//Initializes game resources
	bool Initialize();
	//Cleans up game resources
	void Cleanup();
	//This function should be called every frame while IsGameRunning() is true
	int Run();
	//Quits the game and sets the termination code to c
	void Quit(int c);
	//Returns true if the game is currently running, false otherwise
	bool IsGameRunning();
	//Used to get the return code of the game
	int GetTerminationCode();
	//Get the rounded down frames per second
	uint GetFPS();
	//Get the time it took for the last frame to update
	float GetTimeDelta();

	//Returns the renderer class used to render using opengl/sdl
	IRenderer *GetRenderer();
	//Returns the game's screen manager
	IScreenManager *GetScreenManager();

protected:
	//Called every frame to update game logic
	void Update();
	//Called every frame to render to the screen
	void Render();
	//This function is called when and SDL_Event occurs
	void HandleSDLEvent(SDL_Event e);
	//OpenGL Initialization and SDL Window creation happens here
	bool InitRenderer();

	void InitFrameTiming();
	//Start timing at the beginning of a frame
	void BeginFrameTiming();
	//End timing after Update() and Render() have completed
	void EndFrameTiming();

protected:
	bool m_bRunning;
	int m_nRetCode;
	CTimer m_frameTimer;
	FPSCounter m_fpsCounter;

	ScreenManager *m_pScreenManager;
	Renderer *m_pRenderer;
	IModLoader *m_pModLoader;
};